package com.ysx.wemedia.controller;


import com.ysx.common.pojo.Result;
import com.ysx.core.controller.AbstractCoreController;
import com.ysx.exception.ToutiaoException;
import com.ysx.wemedia.pojo.WmUser;
import com.ysx.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
* <p>
* 自媒体用户信息表 控制器</p>
* @author ljh
* @since 2021-09-08
*/
@Api(value="自媒体用户信息表",tags = "WmUserController")
@RestController
@RequestMapping("/wmUser")
@Slf4j
public class WmUserController extends AbstractCoreController<WmUser> {

    private WmUserService wmUserService;

    //注入
    @Autowired
    public WmUserController(WmUserService wmUserService) {
        super(wmUserService);
        this.wmUserService=wmUserService;
    }

    //根据用户id查询自媒体账号
    @GetMapping("/one/{userId}")
    public WmUser selectByUserId(@PathVariable(value = "userId") Integer userId) {
        return wmUserService.selectByUserId(userId);
    }

    @PostMapping("/login")
    @ApiOperation("登录自媒体系统成功签发token令牌")
    public Result<Map<String,Object>> loginSystemReturnToken(@RequestBody WmUser wmUser) throws ToutiaoException {
        log.debug("获得的登录信息{},{}"+wmUser.getId(),wmUser.getPassword());
        Map<String,Object> map = wmUserService.loginSystemReturnToken(wmUser);
        return Result.ok(map);
    }

}

